games greedy strings *800

Please click on ads to support us..

Python Code:

for it in range(int(input())):
    s=input()
    a=[ord(i)-ord('a')+1 for i in s]
    if len(a)==1:
        print('Bob',a[0])
    elif len(a)%2:
        print('Alice',sum(a)-2*min(a[0],a[-1]))
    else:
        print('Alice',sum(a))

C++ Code:

#include<bits/stdc++.h>
// #include<pthread.h>
using namespace std;
template<typename... T>
void see(T&... args) { ((cin >> args), ...);}
template<typename... T>
void put(T&&... args) { ((cout << args << " "), ...);}
template<typename... T>
void putl(T&&... args) { ((cout << args << " "), ...); cout<<'\n';}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << "=" << a << ", "; err(++it, args...);}
// #define int long long
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define vc vector<char>
#define L cout<<'\n';
#define R return;
#define E cerr<<'\n';
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for (ll i=a; i<b; ++i)
#define rev(i,a,b) for (ll i=a; i>b; --i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setpr(x) cout<<setprecision(x)<<fixed
#define sz size()
#define seea(a,x,y) for(ll i=x;i<y;i++){cin>>a[i];}
#define seev(v,n) for(ll i=0;i<n;i++){ll x; cin>>x; v.push_back(x);}
#define sees(s,n) for(ll i=0;i<n;i++){ll x; cin>>x; s.insert(x);}
// const ll inf = INT_MAX;
// const ld ep = 0.0000001;
// const ld pi = acos(-1.0);
const ll mod = 998244353;
// const ll N = 1e5 + 2;
// const int N = 10010;
// const int N1 = 5010;
// const ll mod = 998244353;
// ll dp[1010][100010];
// int dp[5002][5002];
// int a[5002];
// int dp2[5002];
// ll imp[N];
// ll size[N];
// vector<ll> v[1010][1010];
// int n, m;
// int a[1010][1010];
// bool vis[1000010];
// vector<vector<int>> v(1000010);
void solve();
// vector<bool> isPrime;

// void is()
// {
//     isPrime.assign(21,true);
//     isPrime[0]=isPrime[1]=false;
//     for(ll i = 2; i*i <= 21; i++)
//     {
//         if(isPrime[i])
//         {
//             for(ll j=i*i; j<=21; j+=i)
//                 isPrime[j]=false;
//         }
//     }
// }

int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("inputt.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    IOS
    ll test=1;
    // is();
    see(test);
    while(test--)
    {
        solve();
    }
} 

// void dfs(int i,int j,int &p)
// {
//     if(a[i][j]==0) return;
//     if(i>=n || j>=m || i<0 || j<0) return;
//     if(vis[i][j]==true) return;
//     // putl(i,j);
//     p = p + a[i][j];
//     vis[i][j]=true;
//     dfs(i+1,j,p);
//     dfs(i,j+1,p);
//     dfs(i-1,j,p);
//     dfs(i,j-1,p);
// }

void solve()
{
    string s;
    see(s);
    ll ans = 0;
    rep(i,0,s.length())
        ans+=s[i]-'a'+1;
    if(s.length()%2==0)
    {
        putl("Alice", ans);
    }
    else if(s.length()==1)
    {
        putl("Bob",ans);
    }
    else if(s.length()%2==1)
    {
        if(s[0]>s[s.length()-1])
        {
            ans = ans - 2*(s[s.length()-1]-'a'+1);
            if(ans>0)
                putl("Alice",ans);
            else
                putl("Bob",ans);
        }
        if(s[0]<=s[s.length()-1])
        {
            ans = ans - 2*(s[0]-'a'+1);
            if(ans>0)
                putl("Alice",ans);
            else
                putl("Bob",ans);
        }
    }
}



Comments

Submit
0 Comments
More Questions

145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number
169. Majority Element
119. Pascal's Triangle II
409. Longest Palindrome
1574A - Regular Bracket Sequences
1574B - Combinatorics Homework
1567A - Domino Disaster
1593A - Elections
1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians